package com.luo.backend.service;

import com.luo.backend.dto.CategoryResponse;
import com.luo.backend.entity.FoodCategory;
import com.luo.backend.repository.FoodCategoryRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 分类服务
 */
@Service
public class CategoryService {
    
    private static final Logger logger = LoggerFactory.getLogger(CategoryService.class);
    
    @Autowired
    private FoodCategoryRepository foodCategoryRepository;
    
    /**
     * 获取所有启用的分类列表
     */
    public List<CategoryResponse> getAllCategories() {
        logger.info("获取所有分类列表");
        
        // 查询所有启用的分类，按排序字段升序
        List<FoodCategory> categories = foodCategoryRepository.findByStatusOrderBySortOrderAsc(1);
        
        logger.info("查询到{}个启用的分类", categories.size());
        
        return categories.stream()
            .map(CategoryResponse::new)
            .collect(Collectors.toList());
    }
}






